class CResource(object):
    RESOURCE = []
    IMAGE = 1

    def __init__(self):
        pass

    @staticmethod
    def add_image(file_path):
        import D2Ext
        image_file = D2Ext.Image_LoadFromFile(file_path)
        res = {
            'type': CResource.IMAGE,
            'path': file_path,
            'image': image_file
        }
        D2Ext.LogMsg("type=%s, path=%s, image=%s" % (res['type'], res['path'], res['image']))
        CResource.RESOURCE.append(res)

    @staticmethod
    def get_image(file_path):
        for res in CResource.RESOURCE:
            if res['type'] != CResource.IMAGE:
                continue
            if res['path'] != file_path:
                continue
            return res['image']
        return None

    @staticmethod
    def remove_image(image_file):
        file_index = -1
        i = 0
        for res in CResource.RESOURCE:
            if res['type'] != CResource.IMAGE:
                i += 1
                continue
            if res['image'] != image_file:
                i += 1
                continue
            file_index = i

        if file_index > -1:
            CResource.RESOURCE.pop(file_index)

        import D2Ext
        D2Ext.Image_Unload(image_file)
